﻿using System;
using System.Data.Linq.Mapping;

namespace Organizer.Model
{
    [Table]
    public class Note : Base<Note>
    {
        [Column(IsPrimaryKey = true, DbType = "UniqueIdentifier NOT NULL", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public Guid Id { get; private set; }

        public void Assign(Note dest)
        {
            dest.Id = Id;
            dest.Description = _description;
            dest.TimeCreate = _timeCreate;
        }

        
        private string _description;
        /// <summary>
        /// Текст заметки
        /// </summary>
        [Column]
        public string Description
        {
            get { return _description; }
            set
            {
                NotifyPropertyChanging(() => this.Description);
                _description = value;
                NotifyPropertyChanged(() => this.Description);
            }
        }

        
        private DateTime _timeCreate;
        /// <summary>
        /// Время создания заметки (автоматом)
        /// </summary>
        [Column(DbType = "datetime")]
        public DateTime TimeCreate
        {
            get { return _timeCreate; }
            set
            {
                NotifyPropertyChanging(() => this.TimeCreate);
                _timeCreate = value;
                NotifyPropertyChanged(() => this.TimeCreate);
            }
        }

        #region construtors

        public Note()
        {
            Id = Guid.NewGuid();
            _timeCreate = DateTime.Now;
        }

        public Note(string pDescription)
            : this()
        {
            Description = pDescription;
        }

        #endregion
    }
}
